package moxl.parser.assemblers.closeelement;

import moxl.parser.ParserException;
import moxl.parser.assemblers.AbstractTokenFedMarkupAssembler;
import moxl.parser.assemblers.AssemblerException;
import moxl.tokenizer.TokenStream;
import moxl.tokenizer.TokenizerException;
import moxl.tokenizer.xml.XmlTokenType;

public class CloseElementAssembler extends AbstractTokenFedMarkupAssembler<CloseElementAssemblerState, CloseElementAssemblerContext>
{
	@Override
    protected CloseElementAssemblerContext createAssemblerContext(TokenStream tstream)
    {
	    return new CloseElementAssemblerContext(tstream);
    }

	@Override
    protected void handleInput(XmlTokenType type, CloseElementAssemblerContext ctx) throws ParserException, TokenizerException
    {
		CloseElementStateDelegateBase delegate = ctx.getState().getDelegate();
		switch (type)
		{
		case OPEN_CHEVRON_SLASH:
			delegate.acceptOpenChevronSlash(ctx);
			break;

		case NAME:
			delegate.acceptName(ctx);
			break;

		case CLOSE_CHEVRON:
			delegate.acceptCloseChevron(ctx);
			break;

		case SPACE:
			delegate.acceptSpace(ctx);
			break;

		case WHITESPACE:
			delegate.acceptWhitespace(ctx);
			
		default:
			throw new AssemblerException("Parser cannot handle token: " + ctx.getToken(), ctx.getLocation());
		}
    }

}
